package service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import dbcon.DBCon;

public class Temp {
	DBCon dbcon = new DBCon();
	ResultSet rs = null;
	public List<Integer> selectMonthList(String segment,String tableName) throws  SQLException{
		List<Integer> dateList = new ArrayList<Integer>(); //the month list of the every requirement;
		List<Integer> monthList = new ArrayList<Integer>();  //the month list  no more than 12;
		String sql = "select "+ segment +" from " + tableName;
		rs = dbcon.executeQuery(sql);
		while(rs.next()){
			String date = rs.getString(segment);
			System.out.println("date:"+date);
			if(date.isEmpty()==false){
				String[] dateArray = date.split("/");
				int month = Integer.parseInt(dateArray[1]);
				dateList.add(month);
			}
		}
		for(int i=1;i<=12;i++){
			if(dateList.contains(i)){
				monthList.add(i);
			}
		}
		System.out.println("monthList:"+monthList.toString());
		return monthList;
	}
	public List<Integer> selectMonthCountList(String segment,String tableName) throws SQLException{
		List<Integer> dateList = new ArrayList<Integer>(); //the month list of the every requirement;
		List<Integer> monthList = new ArrayList<Integer>();  //the month list  no more than 12;
		List<Integer> MonthCountList = new ArrayList<Integer>(); //the requirement count of every month;
		int count = 0;
		String sql = "select " + segment + " from " + tableName;
		rs = dbcon.executeQuery(sql);
		while(rs.next()){
			String date = rs.getString(segment);
			if(date.isEmpty()==false){
				String[] dateArray = date.split("/");
				int month = Integer.parseInt(dateArray[1]);
				dateList.add(month);
			}
		}
		for(int i=1;i<=12;i++){
			if(dateList.contains(i)){
				monthList.add(i);
			}
		}
		for(int i=0;i<monthList.size();i++){
			for(int j=0;j<dateList.size();j++){
				if(monthList.get(i)==dateList.get(j)){
					count++;
				}
			}
			MonthCountList.add(count);
			count = 0;
		}
		System.out.println("MonthCountList:"+MonthCountList.toString());
		return MonthCountList;
	}
	public static void main(String args[]) throws SQLException{
		Temp temp = new Temp();
//		temp.selectMonthList("receiveDate","requirement");
		temp.selectMonthList("realTouchanDate","development");
//		temp.selectMonthCountList("receiveDate","requirement");
		temp.selectMonthCountList("realTouchanDate", "development");
	}
}
